package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.LockDevice;
import com.example.entity.LockDeviceInfo;
import com.example.mapper.LockDeviceInfoMapper;
import com.example.mapper.LockDeviceMapper;
import com.example.service.LockDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LockDeviceInfoServiceImpl implements LockDeviceInfoService {
    @Autowired
    private LockDeviceInfoMapper lockDeviceInfoMapper;
    @Autowired
    private LockDeviceMapper lockDeviceMapper;

    @Override
    public List<LockDeviceInfo> getAllDevice() {
        return lockDeviceInfoMapper.selectList(null);
    }

    @Override
    public List<LockDeviceInfo> selectDeviceByName(LockDeviceInfo lockDeviceInfo) {
        return lockDeviceInfoMapper.selectList(new QueryWrapper<LockDeviceInfo>().like("device_name", lockDeviceInfo.getDeviceName()));
    }

    @Override
    public List<LockDevice> selectDeviceByCountyId(LockDevice lockDevice) {
        return lockDeviceMapper.selectList(new QueryWrapper<LockDevice>().eq("county_id", lockDevice.getCountyId()));
    }

    @Override
    public LockDeviceInfo selectDeviceById(LockDeviceInfo lockDeviceInfo) {
        return lockDeviceInfoMapper.selectOne(new QueryWrapper<LockDeviceInfo>().eq("device_id", lockDeviceInfo.getDeviceId()));
    }

    @Override
    public int insertDevice(LockDeviceInfo lockDeviceInfo) {
        return lockDeviceInfoMapper.insert(lockDeviceInfo);
    }

    @Override
    public int updateDevice(LockDeviceInfo lockDeviceInfo) {
        return lockDeviceInfoMapper.update(lockDeviceInfo, new QueryWrapper<LockDeviceInfo>().eq("device_id", lockDeviceInfo.getDeviceId()));
    }
}
